package org.hxyjs.service.impl;

import org.hxyjs.dao.AdminRnoDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.AdminRno;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AdminRnoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("AdminRnoService")
public class AdminRnoServiceImpl implements AdminRnoService {
    @Resource
    AdminRnoDao adminRnoDao;
    @Override
    public DTO<AdminRno> getAllAdminRnos()  throws Exception{
        List<AdminRno> adminRnos = adminRnoDao.getAllAdminRnos();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(adminRnos).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<AdminRno>(messageEnum.getCode(),messageEnum.getMessage(),adminRnos);
    }

    @Override
    public DTO<AdminRno> deleteAdminRnoByRano(String rano)  throws Exception{
        Integer result = adminRnoDao.deleteAdminRnoByRano(rano);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADMINSUCCESS:MessageEnum.DELETEADMINFAIL;
        return new DTO<AdminRno>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<AdminRno> getAdminRnoByRano(String rano)  throws Exception{
        AdminRno adminRnos = adminRnoDao.getAdminRnoByRano(rano);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(adminRnos).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<AdminRno>(messageEnum.getCode(),messageEnum.getMessage(),adminRnos);
    }

    @Override
    public DTO<AdminRno> updateAdminRnoByRano(AdminRno adminRno) throws Exception {
        Integer result = adminRnoDao.updateAdminRnoByRano(adminRno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADMINSUCCESS:MessageEnum.UPDATEADMINFAIL;
        return new DTO<AdminRno>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<AdminRno> addAdminRno(AdminRno adminRno) throws Exception {
        Integer result = adminRnoDao.addAdminRno(adminRno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.ADDADMINSUCCESS:MessageEnum.ADDADMINFAIL;
        return new DTO<AdminRno>(messageEnum.getCode(),messageEnum.getMessage());
    }

    /**
     * 学生选课成功 学生成绩加1分，从选课信息中可以获得学生的学号就能查询出学生原来的成绩
     * @param
     * @return
     * @throws Exception
     */
    @Override
    public DTO<AdminRno> getAdminRnoByPage(PageInfo pageInfo) throws Exception {
        List<AdminRno> adminRnos = adminRnoDao.getAdminRnoByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(adminRnos).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<AdminRno>(messageEnum.getCode(),messageEnum.getMessage(),adminRnos,pageInfo);
    }

}
